package Server.junit;

import Server.map.Box;
import Server.players.Carnivorous;
import Server.players.Dino;
import Server.players.Herbivorous;
import junit.framework.TestCase;

public class CarnTest extends TestCase {

	private Carnivorous c;
	protected void setUp() throws Exception {
		super.setUp();
		c = new Carnivorous(1);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testIsCarniv() {
		assertTrue(c.isCarniv());
	}

	public void testIsHerb() {
		assertFalse(c.isHerb());
	}

	public void testMaxDistance() {
		assertTrue(c.maxDistance() == 3);
	}

	public void testEat() {
		Box b = new Box(1,1,false);
		b.putMeat();
		int e = b.getFoodEnergy();
		int en = c.getEnergy();
		c.eat(b);
		assertTrue(c.getEnergy() == en+e);
	}

	public void testFight() {
		Carnivorous c1 = new Carnivorous(2);
		c.grow();
		assertEquals(c.fight(c1), c);
		Herbivorous h = new Herbivorous(3);
		assertEquals(c.fight(h), c);
	}

	public void testCarnivorousInt() {
		c = new Carnivorous(3);
		assertNotNull(c);
	}

	public void testCarnivorousIntBox() {
		c = new Carnivorous(3, new Box(1,1,false));
		assertNotNull(c);
	}

	public void testCarnivorousCarnivorous() {
		Carnivorous c1 = new Carnivorous(c);
		assertNotNull(c1);
	}

	public void testOlder() {
		int age = c.getAge();
		c.older();
		assertFalse(age == c.getAge());
	}

	public void testEgg() {
		int energy = c.getEnergy();
		if (c.egg()){
			assertTrue(c.getEnergy() == energy - Dino.ENERGY_REQUIRED_EGG);
		} else {
			assertTrue(c.getEnergy() < 0);
		}
	}

	public void testGrow() {
		int energy = c.getEnergy();
		int dimension = c.getDimension();
		if (c.grow()){
			assertTrue(c.getEnergy() == energy - (dimension*1000)/2);
			assertTrue(c.getDimension() == dimension + 1);
		} else {
			assertTrue(c.getEnergy() < 0);
		}
	}

	public void testMove() {
		Box dest = new Box(3,3,false);
		Carnivorous c1 = new Carnivorous(3, new Box(1,1, false));
		int energy = c1.getEnergy();
		if (c1.move(dest, 2)){
			assertTrue(c1.getEnergy() == energy - 10 * Math.pow(2, 2));
			assertEquals(new Box(c1.getX(), c1.getY(), false), dest);
		} else {
			assertTrue(c1.getEnergy() < 0);
		}
	}

}
